﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PartyInvites.Test.Chart6
{
    public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public decimal Price { get; set; }
    }

    public interface IValueCalculator
    {
        decimal ValueProducts(IEnumerable<Product> products);
    }

    public class LinqValueCalculator : IValueCalculator
    {
        public decimal ValueProducts(IEnumerable<Product> products)
        {
            return products.Sum(p => p.Price);
        }
    }

    public class ShoppingCart
    {
        private IValueCalculator calc;
        public IEnumerable<Product> Products { get; set; }

        public ShoppingCart(IValueCalculator calcParam)
        {
            calc = calcParam;
        }

        public decimal CalculateProductTotal()
        {
            return calc.ValueProducts(Products);
        }

    }
}